package demo4;
class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}
class Plate<T> { // 设置泛型
    private T data ;
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Plate<Apple> plate = new Plate<>() ;
        plate.setData(new Apple());
        //fun(plate);
        Plate<Banana> plate2 = new Plate<>() ;
        plate2.setData(new Banana());
        //fun(plate2);
    }

    /*private static void fun(Plate<? extends Fruit> plate) {
        Fruit data = plate.getData();
        System.out.println(data);
    }*/

    public static void fun(Plate<? super Fruit> temp){
// 此时可以修改！！添加的是Fruit 或者Fruit的子类
        temp.setData(new Apple());//这个是Fruit的子类
        temp.setData(new Fruit());//这个是Fruit的本身
//Fruit fruit = temp.getPlate(); 不能接收，这里无法确定是哪个父类
        System.out.println(temp.getData());//只能直接输出
    }
}
